home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / util / gnu / cvs-1.11.1p1.lha / contrib / dirfns.shar / readdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-28  |  1.1 KB  |  53 lines

  1. /* Copyright (c) 1982 Regents of the University of California */
  2.  
  3. static char sccsid[] = "@(#)readdir.c 4.3 8/8/82";
  4.  
  5. #include <sys/types.h>
  6. #include <dir.h>
  7.  
  8. /*
  9.  * read an old stlye directory entry and present it as a new one
  10.  */
  11. #define    ODIRSIZ    14
  12.  
  13. struct    olddirect {
  14.     ino_t    od_ino;
  15.     char    od_name[ODIRSIZ];
  16. };
  17.  
  18. /*
  19.  * get next entry in a directory.
  20.  */
  21. struct direct *
  22. readdir(dirp)
  23.     register DIR *dirp;
  24. {
  25.     register struct olddirect *dp;
  26.     static struct direct dir;
  27.  
  28.     for (;;) {
  29.         if (dirp->dd_loc == 0) {
  30.             dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
  31.                 DIRBLKSIZ);
  32.             if (dirp->dd_size <= 0) {
  33.                 dirp->dd_size = 0;
  34.                 return NULL;
  35.             }
  36.         }
  37.         if (dirp->dd_loc >= dirp->dd_size) {
  38.             dirp->dd_loc = 0;
  39.             continue;
  40.         }
  41.         dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
  42.         dirp->dd_loc += sizeof(struct olddirect);
  43.         if (dp->od_ino == 0)
  44.             continue;
  45.         dir.d_ino = dp->od_ino;
  46.         strncpy(dir.d_name, dp->od_name, ODIRSIZ);
  47.         dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
  48.         dir.d_namlen = strlen(dir.d_name);
  49.         dir.d_reclen = DIRBLKSIZ;
  50.         return (&dir);
  51.     }
  52. }
  53.